@extends('mobile.layout1')
@section('title','提现')


@section('aside-bar')

@endsection


@section('content')
<body>
<div class="view-container mgn55">
    <div class="view-inner">
        <form id="form" action="/myTeam/withdraw" method="post">
            <div class="advocacy">
                <div class="form-list">
                    <span>提现金额</span>
                    <input type="text" name="price" placeholder="最少提现额度50" />
                </div>

                <div class="form-list">
                    <span>银行账号</span>
                    <input type="text" name="bank_code" value="{{$userWithdraw->bank_code or ''}}" placeholder="银行账号" />
                </div>
                <div class="form-list">
                    <span>开户名</span>
                    <input type="text" name="user_name"  value="{{$userWithdraw->user_name or ''}}" placeholder="开户人姓名" />
                </div>

                  <input type="hidden" name="phone" id="phone" value="{{Auth::user()->mobile}}" >
                <div class="form-list" style="position: relative">
                    <span>验证码</span>
                    <input type="text" id="mescode"  name="mesCode" class="form-control" placeholder="请输入短信验证码" required>
                    <button type="button" class="J-countDown ui-border-l" data-time="60" onclick="sendMobile(this)"   style="color: #f60;position: absolute;top: 8px;right: 8px;padding: 3px 5px;">获取验证码
                </div>
               {{--

                    <span>验证码</span>
                    <input type="text" name="captcha" placeholder="" />
                </div>
                <div class="form-list-special">
                    <img src="{{captcha_src()}}"  width="60px" onclick="this.src='{{url('/captcha')}}/'+Math.random();"/>
                </div>--}}
            </div>
            <div class="form-submit" onclick="withdraw()"><input type="button" value="确定提现"></div>
        </form>
    </div>
</div>
</body>
</html>
@endsection
@section('js')
    <script>
        function withdraw() {
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/myTeam/withdraw" ,//url
                data: $('#form').serialize(),
                success: function (result) {
                    if(result.code==0){
                        layer.open({
                            content: result.message,
                            time: 2
                            ,skin: 'msg'
                        });
                    }else{
                        layer.open({
                            content: result.message,
                            time: 2
                            ,skin: 'msg'
                        });
                    window.location.href='/myTeam/withdrawDetail';
                    }

                },

            });

        }
        var countdown=60;
        function settime(obj){
            if (countdown == 0) {
                obj.attr("disabled",false);
                obj.text("获取验证码");
                countdown = 60;
            } else {
                obj.attr("disabled", true);
                obj.text("重新发送(" + countdown + ")");
                countdown--;
                setTimeout(function() {
                    settime(obj)
                },1000)
            }

        }

        function sendMobile(n){
            var chkCode=$("#picCode").val();
            var phone=$("#phone").val();
            var disable=false;
            if($("#picCode").val()==''){
                layer.open({
                    content: '验证码不能为空',
                    time: 2
                    ,skin: 'msg'
                });
                return ;
            }
            if($("#phone").val()==''){
                layer.open({
                    content: '请绑定手机号',
                    time: 2
                    ,skin: 'msg'
                });
                return ;
            }
            if(disable==true){
                return ;
            }
            var index= layer.open({
                type: 2
                ,content: '提交中'
            });
            disable=true;
            $.post('/user/sms',{chkCode:chkCode,phone:phone},function(data){
                if(data.code==0){
                    layer.close(index);
                    layer.open({
                        content: data.message,
                        time: 2
                        ,skin: 'msg'
                    });
                    return false;
                }
                var obj = $(n);
                settime(obj);
                layer.close(index);
                layer.open({
                    content: data.message,
                    time: 2
                    ,skin: 'msg'
                });
                disable=false;
            });
        }
    </script>
    @endsection